package com.hpf.gupao.thread;

import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @datetime: 2021/5/15 21:13
 * @author: huangpengfei
 */
public class ThreadStatusExample {

    public static void main(String[] args){
        new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"TIME_WAITING").start();

        new Thread(() -> {
           while (true) {
               synchronized (ThreadStatusExample.class) {
                   try {
                       ThreadStatusExample.class.wait();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
           }
        },"WAITING");

        new Thread(new BlockDemo(),"Block-demo-01").start();
        new Thread(new BlockDemo(),"Block-demo-02").start();

    }

    static class BlockDemo implements Runnable {

        @Override
        public void run() {
            synchronized (BlockDemo.class) {
                while (true) {
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
